import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Fortaleza2 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Fortaleza2 extends World
{
    private Grass grass1;
    private Grass grass2;
    private Grass grass3;
    private Grass grass4;
    private Grass grass5;
    private Monster mons1;
    private Monster mons2;
    private Monster mons3;
    private Monster mons4;
    private Monster mons5;
    private Heroe heroe;
    private Activador act;
    private PuertaH puerta;
    private Counter monedas;
    private SimpleTimer timer2=new SimpleTimer();
    private int wave;

    public Fortaleza2()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1,false);                
        wave=2; 
        prepare();    
    }

    public void act()
    {
        play();
        endGame();
    }

    public void endGame()
    {
        if(act.isDestroyed()==true || puerta.isDestroyed()==true)
        {
            heroe.actualizaPuntos();
            removeObjects( getObjects(Actor.class) );
            setBackground("game-over.jpg");
            Menu menu=new Menu();
            if(Greenfoot.isKeyDown("enter"))
                Greenfoot.setWorld(menu);         
        }
    }

    public Activador getActivador()
    {
        return act;
    }

    public PuertaH getPuerta()
    {
        return puerta;
    }

    public void play()
    {
        switch(wave)
        {
            case 2:  
            wave2();
            break;         
        }
    }

    public void wave2()
    {

        if(timer2.millisElapsed()>=2000)
        {
            int x=Greenfoot.getRandomNumber(7);          
            if(x==0)
            {
                mons1=new Monster(grass1,10);
                addObject(mons1,0,363);    
            }
            if(x==2)
            {
                mons2=new Monster(grass2,10);
                addObject(mons2,347,0);
            }
            if(x==4)
            {
                mons3=new Monster(grass3,10);
                addObject(mons3,799,200);
            }
            if(x==6)
            {
                mons4=new Monster(grass4,10);
                addObject(mons4,799,480);
            }
            timer2.mark();         
        }

    }

    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {
        grass1=new Grass();
        addObject(grass1,122,382);             
        grass2=new Grass();
        addObject(grass2,333,125);
        grass3=new Grass();
        addObject(grass3,720,200);
        grass4=new Grass();
        addObject(grass4,452,498);
        act=new Activador();
        addObject(act,240,223);
        puerta = new PuertaH(act);
        addObject(puerta, 206, 568);
        Wall4 wall4 = new Wall4();
        addObject(wall4, 222, 204);
        Wall4 wall42 = new Wall4();
        addObject(wall42, 337, 218);
        wall42.setLocation(717, 76);
        wall4.setLocation(591, 75);
        Wall4 wall43 = new Wall4();
        addObject(wall43, 218, 167);
        Wall4 wall44 = new Wall4();
        addObject(wall44, 287, 171);
        Wall4 wall45 = new Wall4();
        addObject(wall45, 152, 158);
        Wall4 wall46 = new Wall4();
        addObject(wall46, 386, 183);
        Wall3 wall3 = new Wall3();
        addObject(wall3, 579, 297);
        wall3.setLocation(510, 133);
        Wall3 wall32 = new Wall3();
        addObject(wall32, 155, 328);
        Wall3 wall33 = new Wall3();
        addObject(wall33, 178, 386);
        Wall3 wall34 = new Wall3();
        addObject(wall34, 248, 471);
        Wall3 wall35 = new Wall3();
        addObject(wall35, 386, 377);
        Wall3 wall36 = new Wall3();
        addObject(wall36, 389, 438);
        wall35.setLocation(436, 438);
        wall46.setLocation(717, 214);
        wall36.setLocation(635, 275);
        wall36.setLocation(635, 271);
        wall44.setLocation(578, 355);
        wall32.setLocation(368, 133);
        wall43.setLocation(661, 433);
        wall45.setLocation(79, 116);
        wall33.setLocation(228, 134);
        wall45.setLocation(144, 191);
        wall45.setLocation(145, 194);
        wall43.setLocation(145, 333);
        wall35.setLocation(496, 415);
        wall34.setLocation(359, 417);
        Wall4 wall47 = new Wall4();
        addObject(wall47, 271, 311);
        Wall4 wall48 = new Wall4();
        addObject(wall48, 319, 297);
        Wall4 wall49 = new Wall4();
        addObject(wall49, 371, 283);
        Wall4 wall410 = new Wall4();
        addObject(wall410, 425, 268);
        wall47.setLocation(145, 474);
        wall48.setLocation(301, 500);
        wall49.setLocation(145, 552);
        wall410.setLocation(425, 268);
        wall410.setLocation(425, 268);
        wall410.setLocation(425, 268);
        wall410.setLocation(425, 268);
        wall410.setLocation(425, 268);
        wall410.setLocation(425, 268);
        wall410.setLocation(301, 569);
        wall49.setLocation(220, 263);
        Wall3 wall37 = new Wall3();
        addObject(wall37, 349, 316);
        wall47.setLocation(144, 404);
        wall37.setLocation(75, 461);
        wall37.setLocation(87, 461);
        wall410.setLocation(356, 246);
        Wall3 wall38 = new Wall3();
        addObject(wall38, 511, 515);
        Wall3 wall39 = new Wall3();
        addObject(wall39, 662, 471);
        wall38.setLocation(218, 558);
        wall37.setLocation(85, 461);
        wall39.setLocation(92, 558);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(220, 263);
        wall49.setLocation(660, 430);
        wall410.setLocation(665, 451);
        wall410.setLocation(679, 441);
        removeObject(wall410);
        removeObject(wall49);
        wall37.setLocation(75, 456);
        wall47.setLocation(146, 368);
        wall37.setLocation(88, 426);
        wall33.setLocation(497, 247);
        wall32.setLocation(370, 133);
        wall33.setLocation(322, 132);
        wall33.setLocation(342, 133);
        wall33.setLocation(323, 132);
        wall35.setLocation(710, 545);
        wall35.setLocation(402, 417);
        wall47.setLocation(411, 311);
        wall47.setLocation(144, 354);
        wall48.setLocation(466, 280);
        wall34.setLocation(354, 436);
        wall34.setLocation(354, 443);
        wall35.setLocation(414, 443);
        wall35.setLocation(406, 442);
        wall48.setLocation(579, 383);
        wall46.setLocation(720, 411);
        wall46.setLocation(714, 444);
        Wall3 wall310 = new Wall3();
        addObject(wall310, 672, 277);
        wall310.setLocation(668, 270);
        wall47.setLocation(662, 475);
        wall43.setLocation(145, 262);
        wall43.setLocation(145, 241);
        removeObject(wall46);
        removeObject(wall47);
        wall33.setLocation(227, 135);
        wall32.setLocation(456, 267);
        wall32.setLocation(475, 134);
        wall32.setLocation(477, 133);
        Activador activador = new Activador();
        addObject(activador, 185, 174);
        activador.setLocation(176, 168);
        removeObject(activador);
        Wall4 wall411 = new Wall4();
        addObject(wall411, 151, 349);
        wall411.setLocation(144, 345);
        Wall3 wall311 = new Wall3();
        addObject(wall311, 363, 564);
        wall311.setLocation(352, 559);
        Wall4 wall412 = new Wall4();
        addObject(wall412, 435, 293);
        wall34.setLocation(354, 443);
        wall34.setLocation(354, 443);
        wall34.setLocation(354, 443);
        wall34.setLocation(354, 443);
        wall34.setLocation(354, 443);
        wall34.setLocation(354, 443);
        wall34.setLocation(599, 541);
        removeObject(wall34);
        wall311.setLocation(282, 558);
        wall412.setLocation(721, 458);
        wall35.setLocation(368, 438);
        wall35.setLocation(374, 417);
        wall48.setLocation(695, 449);
        wall35.setLocation(415, 416);
        wall35.setLocation(418, 407);
        wall44.setLocation(609, 357);
        wall44.setLocation(362, 496);
        wall35.setLocation(419, 412);
        wall37.setLocation(594, 464);
        wall44.setLocation(146, 474);
        wall39.setLocation(455, 484);
        wall311.setLocation(483, 433);
        wall38.setLocation(520, 461);
        wall44.setLocation(145, 478);
        wall310.setLocation(512, 326);
        wall412.setLocation(717, 213);
        wall36.setLocation(637, 271);
        wall310.setLocation(308, 328);
        wall38.setLocation(322, 430);
        wall48.setLocation(584, 338);
        wall37.setLocation(382, 444);
        wall311.setLocation(364, 405);
        wall35.setLocation(371, 406);
        wall39.setLocation(420, 488);
        wall48.setLocation(579, 355);
        wall38.setLocation(385, 269);
        wall37.setLocation(496, 413);
        wall39.setLocation(409, 318);
        wall311.setLocation(356, 249);
        wall35.setLocation(350, 278);
        wall310.setLocation(379, 553);
        Wall4 wall413 = new Wall4();
        addObject(wall413, 442, 498);
        wall413.setLocation(439, 494);
        wall310.setLocation(355, 553);
        wall44.setLocation(144, 485);
        wall411.setLocation(188, 397);
        wall44.setLocation(142, 524);
        wall411.setLocation(146, 383);
        wall44.setLocation(146, 521);
        wall44.setLocation(146, 494);
        wall38.setLocation(360, 238);
        removeObject(wall311);
        removeObject(wall35);
        removeObject(wall38);
        removeObject(wall39);
        wall411.setLocation(51, 271);
        wall411.setLocation(671, 540);
        removeObject(wall411);
        wall413.setLocation(699, 579);
        wall413.setLocation(691, 455);
        removeObject(wall413);
        Wall3 wall312 = new Wall3();
        addObject(wall312, 393, 560);
        wall312.setLocation(388, 552);
        wall412.setLocation(678, 460);
        Wall3 wall313 = new Wall3();
        addObject(wall313, 666, 275);
        wall313.setLocation(666, 271);
        wall37.setLocation(512, 412);
        removeObject(wall412);
        wall33.setLocation(205, 134);
        wall48.setLocation(497, 276);
        wall313.setLocation(654, 412);
        wall36.setLocation(589, 234);
        wall48.setLocation(717, 354);
        removeObject(wall36);
        wall33.setLocation(186, 137);
        wall45.setLocation(129, 197);
        wall43.setLocation(129, 247);
        wall44.setLocation(130, 528);
        wall312.setLocation(391, 575);
        wall310.setLocation(345, 578);
        wall312.setLocation(393, 581);
        wall310.setLocation(342, 581);
        wall44.setLocation(117, 526);
        wall43.setLocation(119, 246);
        wall45.setLocation(119, 197);
        wall33.setLocation(178, 133);
        heroe=new Heroe(100);
        addObject(heroe,660,25);
    }
}